/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jgaptest;

import java.awt.image.BufferedImage;

/**
 *
 * @author jkanazawa
 */
public class Operador {

    private int[][] imgTemp;
    private int[][] imgOut;
    private int[][] imgInicial;
    private int width;
    private int height;

    public Operador(BufferedImage imgInicial) {
        this.imgInicial = Operations.loadData(imgInicial);//imgInicial;
        //this.imgTemp = new BufferedImage(imgInicial.getWidth(), imgInicial.getHeight(), imgInicial.getType());
        this.imgTemp = Operations.loadData(imgInicial);//.setData(imgInicial.getData());
        //this.imgOut = new int[imgInicial.getWidth()][imgInicial.getHeight()];//new BufferedImage(imgInicial.getWidth(), imgInicial.getHeight(), imgInicial.getType());
        width = imgInicial.getWidth();
        height = imgInicial.getHeight();
    }

    public int[][] aplicarOperacion(int nroOp, int[][] img) {
        int[][] imgTmp = new int[width][height];
        switch (nroOp) {
            //nop
            case 0:
                imgTmp = img;//.setData(img.getRaster());

            //dil_q_3
            case 1:
                imgTmp = Operations.dilateGrey(Operations.square, 3, 3, width, height, img);
                ////this.imgOut = imgTmp;
                return imgTmp;
            //ero_q_3
            case 2:
                imgTmp = Operations.erodeGrey(Operations.square, 3, 3, width, height, img);
                ////this.imgOut = imgTmp;
                return imgTmp;
            //dil_c_3    
            case 3:
                imgTmp = Operations.dilateGrey(Operations.circle, 3, 3, width, height, img);
                ////this.imgOut = imgTmp;
                return imgTmp;
            //ero_c_3
            case 4:
                imgTmp = Operations.erodeGrey(Operations.circle, 3, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //dil_h_3
            case 5:
                imgTmp = Operations.dilateGrey(Operations.horiz, 1, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //ero_h_3
            case 6:
                imgTmp = Operations.erodeGrey(Operations.horiz, 1, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //dil_v_3
            case 7:
                imgTmp = Operations.dilateGrey(Operations.vertic, 3, 1, width, height, img);
                return imgTmp;
            //ero_v_3
            case 8:
                imgTmp = Operations.erodeGrey(Operations.vertic, 3, 1, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //dil_dd_3
            case 9:
                imgTmp = Operations.dilateGrey(Operations.rdiag, 3, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //ero_dd_3
            case 10:
                imgTmp = Operations.erodeGrey(Operations.rdiag, 3, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //dil_de_3
            case 11:
                imgTmp = Operations.dilateGrey(Operations.ldiag, 3, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //ero_de_3
            case 12:
                imgTmp = Operations.erodeGrey(Operations.ldiag, 3, 3, width, height, img);
                //this.imgOut = imgTmp;
                return imgTmp;
            //xor1
            case 13:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.XOR);
                //this.imgOut = imgTmp;
                return imgTmp;
            //cpl
            case 14:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.NOT);
                //this.imgOut = imgTmp;
                return imgTmp;
            //sto1
            case 15:
                this.imgTemp = img;//.setData(img.getRaster());
                imgTmp =img;
                //this.imgOut = img;//.setData(img.getRaster());
                return imgTmp;
            //and1
            case 16:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.AND);
                //this.imgOut = imgTmp;
                return imgTmp;
            //or1
            case 17:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.OR);
                //this.imgOut = imgTmp;
                return imgTmp;
            //ldi
            case 18:
                imgTmp = imgInicial;//.setData(imgInicial.getRaster());
                //this.imgOut = imgTmp;
                return imgTmp;
            //cpl_cz
            case 19:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.NOT);
                //this.imgOut = imgTmp;
                return imgTmp;
            //add_cz
            case 20:
                imgTmp = Operations.logical(img, this.imgTemp, width, height, Operations.ADD);
                //this.imgOut = imgTmp;
                return imgTmp;
            default:
                imgTmp = null;//this.imgTemp;

        }
        //this.imgOut = imgTmp;
        return imgTmp;
    }
}
